<template>
  <div class="search-container">
    <!-- TODO 微分销与小程序svg和输入法回车监听的区别 -->
    <!-- TODO 暂时隐藏svg -->
    <div class="search-wrapper">
      <div class="icon miniprogram" @click="searchList">
        <img class="img_search" src="https://img.wifenxiao.com/h5-wfx/images/common/search-icon.png" />
      </div>
      <input @confirm="searchList"
             v-model.trim="keyword"
             type="search"
             :placeholder="searchInfo.placeholder" />
    </div>
    <!-- TODO 暂时隐藏svg -->
    <!-- <div class="search-wrapper" v-else>
      <div class="icon" @click="searchList">
        <svg-icon icon-class="icon_search" class="icon_search" />
      </div>
      <input @keyup.enter="searchList"
             v-model.trim="keyword"
             type="search"
             :placeholder="searchInfo.placeholder" />
    </div> -->
  </div>
</template>

<script>
import Vue from 'vue'
export default Vue.extend({
  name: 'index',
  components: {},
  props: {
    searchInfo: {
      type: Object,
      default: {
        placeholder: '',
        illegal_msg: ''
      }
    },
    needIllegal: {
      type: String,
      default: ''
    },
  },
  data() {
    return {
      // placeholder: '请输入商品关键词',
      keyword: ''
    }
  },
  watch: {
    searchInfo: {
      handler(val, oldVal) {
        if (this.needIllegal != '' && val.illegal_msg != this.needIllegal && val.illegal_msg != '') {
          this.keyword = ''
        }
      },
      // 深度观察监听
      deep: true
    }
  },
  methods: {
    searchList() {
      document.querySelector("input").blur()
      this.$emit('search', this.keyword)
    }
  }
})
</script>

<style lang="scss">
@import "src/styles/mixin";
.search-container {
  padding: 18px 20px;
  background: #fff;
}
.search-wrapper {
  position: relative;
  width: 100%;
  height: 72px;
  border-radius: 36px;
  font-size: 0;
  background: #f7f7f7;
  .icon {
    position: absolute;
    line-height: 72px;
    left: 28px;
    color: #999999;
    font-size: 28px;
    margin-right: 10px;
    &.miniprogram{
      line-height: initial;
      top: 22px;
    }
    .icon_search, .img_search{
      width:28px;
      height:28px;
    }
  }
  @include placeColor(#999);
  input {
    display: inline-block;
    width: 100%;
    height: 100%;
    font-size: 24px;
    padding: 15px 70px;
    border: 0;
    background: transparent;
    &.h5-input {
      padding: 0 70px;
    }
  }
}
</style>